<?php


namespace Xiaoguai\DesignPattern\DP006;


class MyIterator implements IteratorInterface
{
    protected $list = [];
    protected $index = 0;

    public function __construct(array $list)
    {
        $this->list = $list;
        $this->index = 0;
    }

    public function first()
    {
        $this->index = 0;
        return $this->list[$this->index];
    }

    public function next()
    {
        $this->index++;
        return $this->list[$this->index];
    }

    public function hasNext(): bool
    {
        return $this->index + 1 < count($this->list);
    }


}